Load some packages that we’ll need to use to do these calculations:

library(tidyverse)
library(gifski)
library(ggraph)
library(here)
library(igraph)
source(here("modelFunction_rewiring.R"))

1. Run the model once

# Define parameters
N = 50
edge.prob <- 0.04
n.removed = 10
burn.in = 20
recovery = 5
add00 = c(0.5, 10)
lose01 = 0.1
add10 = 0.05
lose11 = c(0.5, 0.5)
coefAdd = 0.5
coefLose = -0.5
modelGraphs <- runModel(N = N, # Nodes in the network
                        edge.prob = edge.prob,
                        n.removed = n.removed,
                        burn.in = burn.in,
                        recovery = recovery,
                        add00 = add00, 
                        lose01 = lose01, 
                        add10 = add10,
                        lose11 = lose11,
                        coefAdd = coefAdd,
                        coefLose = coefLose)$graphs

2. For a single model run, examine network-level measures over time

## Warning: Removed 1 row(s) containing missing values (geom_path).

4. Relationship between removed nodes and network-level measures

First, let’s check whether degree and betweenness are indeed highly correlated. We suspect that they are.

Indeed, these are highly correlated. I’m not going to make graphs for betweenness, just degree.

What about the ratio between the first and second changes? Aka: what percentage of the loss/gain is recovered by the rewiring?

## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced
## Warning: Removed 1766 rows containing non-finite values (stat_smooth).
## Warning: Removed 1746 rows containing missing values (geom_point).

## Warning: Removed 20 rows containing non-finite values (stat_smooth).